<template>
    <div class="contenBox">
        <div class='first'>
          <el-card class="box-card">
            <el-form :inline="true" class="demo-form-inline">
            <el-form-item label="班级名称">
                <el-input v-model="maname" placeholder="请输入专业名称"></el-input>
            </el-form-item>
            <el-form-item label="专业名称">
            <el-select v-model="majorId" placeholder="请选择">
          <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.majorName"
              :value="item.majorId"
            >
            </el-option>
        </el-select>
          </el-form-item>
            <el-form-item label="日期">
                         <el-date-picker
                            v-model="beginTime"
                            type="date"
                            placeholder="选择日期"
                            value-format="yyyy-MM-dd HH:mm:ss"
                            :default-time="'00:00:00'"
                            >
                        </el-date-picker>
                        -
                        <el-date-picker
                            v-model="endTime"
                            type="date"
                            placeholder="选择日期"
                            value-format="yyyy-MM-dd HH:mm:ss"
                            :default-time="'23:59:59'"
                            >
                        </el-date-picker>
                    </el-form-item>
            <el-form-item>
                        <el-button type="primary" @click="changeSearch" style='width:100px;background:#7bb4d0;border:none;'>
                <i class="el-icon-search"></i>
                搜索</el-button>
              <el-button type="success" @click='refreshInput' style='width:100px;background:#6ccfcc;border:none;'>
                <i class="el-icon-refresh"></i>
                重置</el-button>
                    </el-form-item>
            </el-form>
         
          </el-card>
         </div>
         <div class='list'>
         <h3 style='color:#3c98d9;margin-top:30px;'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;管理列表</h3>
         <div>
             <template>
                <el-table
                :data="tableData"
                style="width: 94%">
                <el-table-column
                    type='index'
                    label="序号"
                    >
                </el-table-column>
                <el-table-column
                    prop="createTime"
                    label="时间阶段"
                    itemId="id"
                    width="150">
                </el-table-column>
                <el-table-column
                    prop="className"
                    label="班级名称">
                </el-table-column>
                <el-table-column
                    prop="majorName"
                    label="所属专业">
                </el-table-column>
                <el-table-column
                    prop="num"
                    label="班级人数">
                </el-table-column>
                <el-table-column
            fixed="right"
            label="操作"
            width="350">
            <template slot-scope="scope">
                <div class="operation">
                  <el-button type='text' @click='Automatic(scope.$index, scope.row)'>自动分班</el-button>
                  <el-button type='text'  @click='Manual(scope.$index, scope.row)'>手动分班</el-button>
                  <el-button type='text' @click='goseeclassShift(scope.$index, scope.row)'>查看详细</el-button>
                </div>
            </template>
            </el-table-column>
                </el-table>
            </template>
         </div>
         </div>
         <div class="pagination">
          <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="query.pageNum"
        :page-sizes="[2, 3, 4, 5]"
        :page-size="query.pageSize"
        prev-text="上一页"
        next-text="下一页"
        layout=" prev, pager, next"
        :total="query.total"
      ></el-pagination>

          <div class="jumper">
            跳到第
            <input type="text" ref="pageNum" :value="query.pageNum" />
            页
          </div>
          <button @click="goPage">确定</button>
        </div>
        <div>
    <el-dialog
      title="自动分班"
      :visible.sync="dialogFromVisible"
    >
    <div style='widtyh:100px;height:400px;'>
      <template>
    <el-table
    :data="autotableData"
    height="500px"
    border
    style="width: 100%;">
    <el-table-column
      type='index'
      label="序号"
      width="80">
    </el-table-column>
    <el-table-column
      prop="strategyName"
      label="策略名称"
      width="180">
    </el-table-column>
    <el-table-column
      prop="studentSourse"
      label="学生来源">
    </el-table-column>
    <el-table-column
      prop="classNumber"
      label="班级人数">
    </el-table-column>
    <el-table-column
      prop="education"
      label="学历">
    </el-table-column>
    <el-table-column
      prop="address"
      label="操作">
      <template slot-scope="scope">
               <el-button type="primary" @click='autoOut(scope.$index, scope.row)' class="choice">选择</el-button>
      </template>
    </el-table-column>
  </el-table>
  </template>
    </div>
    </el-dialog>
        </div>
    <div>
  <el-dialog 
      title="手动分班"
      :visible.sync="dialogFormVisible"   
    >
    <div style='widtyh:100px;height:400px;'>
  <el-table
    ref="multipleTable"
    :data="handtableData"
    tooltip-effect="dark"
    @selection-change="handleSelectionChange"
    style="width: 100%"
  >
    <el-table-column
      type="selection"
      width="55">
    </el-table-column>
    <el-table-column
      label="序号"
      type='index'
      width="120">      
    </el-table-column>
    <el-table-column 
      prop="studentName"
      label="姓名"
      width="120">
    </el-table-column>
    <el-table-column
      prop="gender" 
      label="性别"
      >
    </el-table-column>
    <el-table-column
      prop="identificationType" 
      label="证件类型"
      >
    </el-table-column>
    <el-table-column
      prop="idCardNo" 
      label="证件号码"
      >
    </el-table-column>
    <el-table-column
      prop="studentIds" 
      label="学号"
      >
    </el-table-column>
    <el-table-column
      prop="colleageName" 
      label="学院"
      >
    </el-table-column>
  </el-table>
    </div>
    <div class="formBtn">
            <el-button class="resetBtn" @click="resetForm">取消</el-button>
            <el-button type="primary" class="submitBtn" @click='btn'>确定</el-button>
        </div>
    </el-dialog>
        </div>
    </div>
</template>
<script>
import {
  classeslistApi,
  classeshandApi,
  classlistApi,
  classesautoApi,
  classeshandListApi
} from "@/api/educational/classShift";
export default {
  data() {
    return {
      // pickerOptions: {
      //   disabledDate(time) {
      //     return time.getTime() > Date.now();
      //   }
      // },
      query: {
        pageNum: 1,
        pageSize: 6,
        total: 0
      },
      stuname: "",
      cert: "",
      classids: "",
      majorIds: "",
      beginTime: "",
      endTime:'',
      options: [],
      ids: "",
      id: "",
      classid: "",
      majorId:'',
      maname: "",
      status:'0',
      tableData: [],
      handtableData: [],
      autotableData: [],
      multipleSelection: [],
      dialogFormVisible: false,
      dialogFromVisible: false
    };
  },
  mounted() {
    this.classList();
  },
  methods: {
    async classList() {
      let res = await classeslistApi(this.query);
      console.log(res);
      this.tableData = res.rows;
      this.query.total = res.total;
      this.options = res.rows;
    },
    // 自动分班
    async Automatic(index, row) {
      this.dialogFromVisible = true;
      console.log("2222", index, row);
      this.classids = row.classId;
      this.majorIds = row.majorId;
      let res = await classlistApi({ majorId: row.majorId });

      this.autotableData = res.rows;
    },
   autoOut(index, row) {
      console.log(index, row);
      this.$confirm("确认要选择分班吗?", "提示", {
        type: "warning"
      })
        .then(async() => {
        let res = await classesautoApi({
        classNumber: row.classNumber,
        education: row.education,
        studentSourse: row.studentSourse,
        classId: this.classids,
        majorId: this.majorIds
      });
      if(res.code==200){
        this.$message.success("操作成功");
      }
     this.dialogFromVisible = false;
      })
        .catch(() => {});

      
    },
    //手动分班
    async Manual(index, row) {
      this.dialogFormVisible = true;
      console.log(index, row);
      this.classid = row.classId;
      let res = await classeshandListApi({ majorId: row.majorId }); 
      this.handtableData = res.data
      console.log('1234',res)
    },
    async btn() {
      let res = await classeshandApi({ classId: this.classid, ids: this.id });
      console.log(res);
     this.$message.success("操作成功");
      this.dialogFormVisible = false;

    },
    //重置
    refreshInput() {
      this.maname = "";
      this.majorId = "";
      this.beginTime = "";
      this.endTime='';
      this.classList();
    },
    //搜索
    changeSearch() {
      classeslistApi({ className: this.maname, majorId: this.majorId,beginTime:this.beginTime,endTime:this.endTime,status:this.status }).then(
        res => {
          console.log('234',res);
          this.tableData = res.rows;
        }
      );
    },
    // changeSearchs() {
    //   classeshandApi({ studentName: this.stuname,idCardNo:this.cert }).then(res => {
    //     console.log('222',res);
    //     // this.handtableData = res.rows;
    //   });
    // },
    // 分页
    // 改变每页条数
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.query.pageSize = val;
      this.classList();
    },
    //切换页数，执行方法
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.query.pageNum = val;
      this.classList();
    },
    goPage() {
      let { value } = this.$refs.pageNum;
      console.log("1", value);
      this.query.pageNum = Number(value);
      this.classList();
    },
    resetForm() {
      this.dialogFormVisible = false;
    },

    async goseeclassShift(index, row) {
      console.log(row);
      this.$router.push({
        name: "SeeclassShift",
        params: {
          id: row.classId
        }
      });
    },
    //选中
    handleSelectionChange(val) {
      console.log(val);
      var arrTostring = [];
      var arr = [];
      var arr2 = [];
      val.forEach(item => {
        if (arrTostring.indexOf(item.id) === -1) {
          arr.push(item.majorId);
          arr2.push(item.id);
        }
      });
      this.ids = arr.toString();
      this.id = arr2.toString();
      console.log("444", this.ids, this.id, this.classid);
    }
  }
};
</script>
<style lang='scss' scoped >
.contenBox {
  width: 104%;
  height: 100%;
  background-color: #f3f2f7;
  box-sizing: border-box;
}
.first {
  width: 94%;
  margin-left: 20px;
}
.list {
  width: 93%;
  margin-left: 40px;
  margin-top: 20px;
  background: #ffffff;
}
.box-card {
  width: 99%;
  display: flex;
  margin-left: 20px;
}
.pagination {
  display: flex;
  align-items: center;
  justify-content: right;
  margin-top: 20px;
  margin-right: 150px;
  .jumper {
    font-size: 14px;
    margin-left: 20px;
    margin-right: 10px;
    display: flex;
    align-items: center;

    input {
      width: 40px;
      height: 26px;
      margin: 0 5px;
      text-align: center;
      border: solid 1px #e6e6e6;
      border-radius: 5px;
      color: #666;
      outline-style: none;
    }
  }
  button {
    height: 28px;
    line-height: 28px;
    border-radius: 5px;
    background-color: #4895db;
    border: solid 1px #4895db;
    color: #fff;
    font-size: 14px;
    padding: 0 8px;
  }
}
::v-deep .el-dialog {
  width: 1100px;
  height: 600px;
  border-radius: 10px;
  font-weight: 600;
  .fade-enter-active,
  .fade-leave-active {
    transition: opacity 0.3s;
  }
  .message {
    position: absolute;
    left: 40%;
    top: 50%;
    width: 140px;
    height: 50px;
    text-align: center;
    line-height: 50px;
    color: #fff;
    border-radius: 10px;
    background-color: rgba(0, 0, 0, 0.4);
  }
  .fade-enter,
  .fade-leave-to {
    opacity: 0;
  }
  .el-dialog__header {
    border-radius: 10px 10px 0 0;
    text-align: center;
    background-color: rgb(72, 149, 219);
    .el-dialog__title {
      color: #fff;
    }
    .el-dialog__headerbtn .el-dialog__close {
      color: #fff;
    }
  }
  .choice {
    width: 100px;
    height: 35px;
    border-radius: 16px;
    line-height: 0;
  }
}
.dialoghead {
  width: 650px;
  height: 40px;
  float: right;
  margin-top: -20px;
  display: flex;
}
.formBtn {
  width: 100%;
  height: 40px;
  margin-top: 50px;
  text-align: center;
  .submitBtn {
    width: 100px;
    height: 30px;
    line-height: 0;
    color: rgb(72, 149, 219) !important;
    border-radius: 18px;
    color: #fff !important;
  }
  .resetBtn {
    width: 100px;
    height: 30px;
    color: #fff;
    line-height: 0;
    border-radius: 18px;
    border: 1px solid rgb(120, 175, 230);
    color: rgb(120, 175, 230);
  }
}
</style>
